#ifndef _DCE4_H
#define _DCE4_H
/*
  author Sylvain Bertrand <digital.ragnarok@gmail.com>
  Protected by GNU Affero GPL v3 with some exceptions.
  See README at root of alga tree.
*/
static const unsigned width_max = 8192;
static const unsigned height_max = 8192;

/* XXX: should go up in alga */
enum link_rate {/* factor of 270 MHz units */
	GHZ_1_62 = 6, 
	GHZ_2_7 = 10,
	GHZ_5_4 = 20
};

/* XXX: should go up in alga */
static inline char *link_rate_names(enum link_rate link_rate)
{
	switch (link_rate) {
	case GHZ_1_62:
		return "1.62 GHz";
	case GHZ_2_7:
		return "2.70 GHz";
	case GHZ_5_4:
		return "5.40 GHz";
	default:
		return "unregistered GHz";
	}
}
/* page flipping only */
struct crtc_surfs {
	u64 primary;
	u64 secondary;
};

struct pf {
	struct crtc_surfs crtc_surfs;
	wait_queue_head_t event;
	atomic_t occurred; /* to avoid race */
};

struct dp {
	bool edp;
	unsigned atb_dfp;

	u8 atb_aux_i2c_id;
	struct i2c_adapter i2c_adapter;
	void *edid;				/* NULL is not fatal */

	unsigned lanes_n;
	enum link_rate link_rate;
	enum link_rate trans_link_rate_max;

	bool connected;
	u8 hpd;					/* no hpd->0xff */	

	u8 dpcd_info[8];			/* see dp specs */

	struct pf pf;
};

struct irq {
	spinlock_t lock;
	unsigned hpds;
};


struct dce4 {
	struct mutex mutex;

	unsigned hpds_used;	/* carefull: hpd index may not be crtc index */
	unsigned dps_used;
	struct dp dps[CRTCS_N_MAX];

	struct dce4_dev ddev;

	struct irq irq;
};

static inline void lock(struct dce4 *dce)
{
	mutex_lock(&dce->mutex);
}

static inline void unlock(struct dce4 *dce)
{
	mutex_unlock(&dce->mutex);
}
#endif
